﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using Teld.BDP.BigDataAccess.ESDB;
//using Teld.BDP.BigDataAccess.Service;
//using Teld.BDP.DataAccess.SPI;
//using Teld.BDP.DataAccess.SPI.Const;
using Teld.Core.DataAccessEx.Core;

namespace T.FAS.Runtime.DataAccess.Engine
{
    class ESDatabase: IDatabase
    {
        /// <summary>
        /// 获取数据库服务
        /// </summary>
        /// <param name="sqlStatement">SQL语句</param>
        /// <returns>数据库服务</returns>
        public ITeldDatabase GetDatabase(SqlStatement sqlStatement)
        {
            return null;
        }

        /// <summary>
        /// 获取数据库服务
        /// </summary>
        /// <param name="dataSourceName">数据源</param>
        /// <returns>数据库服务</returns>
        public ITeldDatabase GetDatabase(string dataSourceName)
        {
            return null;
        }

        /// <summary>
        /// 在数据库事务中执行SQL语句返回影响行数
        /// </summary>
        /// <param name="sqls">SQL语句</param>        
        public void ExecuteSQLWithTransaction(SqlStatementCollection sqls)
        {

        }

        /// <summary>
        /// 执行SQL获取数据
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <returns>数据</returns>
        public DataSet GetData(SqlStatement sql)
        {
            //if (sql == null)
            //    throw new ArgumentNullException("ESDatabase.GetData.sql");

            //var db = BDPDatabaseHelper.GetBDPDatabase(sql.SqlBuildingInfo.DataSource, BDPDbType.ES);
            //var context = new ESContext() { };

            //var ds = db.GetDataSet(sql.ToSQL(), context);
            //if (ds != null && ds.Tables.Count > 0)
            //    ds.Tables[0].TableName = sql.TableName;

            //return ds;
            
            return null;
        }

        /// <summary>
        /// 执行SQL获取数据
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <returns>数据</returns>
        public List<DataTable> GetDataCollection(SqlStatementCollection sqlCollection)
        {
            var dataTables = new List<DataTable>();

            foreach (var sql in sqlCollection)
            {
                var ds = GetData(sql);
                if (ds != null && ds.Tables.Count > 0)
                {
                    for (int i = 0; i < ds.Tables.Count; i++)
                    {
                        dataTables.Add(ds.Tables[i]);
                    }
                }
            }

            return dataTables;
        }

        /// <summary>
        /// 统一数据访问修改V1.1：
        /// 根据ModelTreeSQLBuilder获取SQL以及入参，并执行获取返回结果
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <returns>数据</returns>
        public List<DataTable> GetDataCollection(string sql, FilterConditionStatement filterConditionStatement, string dataSourceName)
        { return null; }

        /// <summary>
        /// 执行SQL获取数据的第一行第一列
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <returns>数据的第一行第一列</returns>
        public object ExecuteScalar(SqlStatement sql)
        {
            return null;
        }

        /// <summary>
        /// 执行SQL返回IDataReader
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <returns>IDataReader</returns>
        public IDataReader GetDataReader(SqlStatement sql)
        {
            return null;
        }
    }
}
